﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SharedTextEditor
{
  [Serializable]
  public class Document {

    public Document(string title,string text)
    {
      Title = title;
      Lines = new List<DocumentLine>();
      ParseTextToLines(text);
    }

    private void ParseTextToLines(string text)
    {
      string[] splitLines = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
       
      for(int i= 0; i< splitLines.Length; i++)
      {
        Lines.Add(new DocumentLine(i, splitLines[i], false));
      }
    }

    public string Title { get; private set; }

    public List<DocumentLine> Lines { get; private set; }


    public override string ToString()
    {
      string text = "";
      foreach(var line in Lines)
      {
        text += line.Text + Environment.NewLine;
      }
      return text;
    }


  }
}
